package com.stylefeng.guns.rest.modular.users.service;

import com.baomidou.mybatisplus.mapper.Condition;
import com.stylefeng.guns.rest.common.persistence.dao.IdCardMapper;
import com.stylefeng.guns.rest.common.persistence.model.IdCardBean;
import com.stylefeng.guns.rest.modular.users.controller.dto.UserIdcardRequest;
import com.stylefeng.guns.rest.modular.users.controller.dto.UserInfoRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by ASUS-PC on 2019/9/18.
 */
@Service
public class UserIdCardService {
    @Autowired
    IdCardMapper idCardMapper;

    /**
     * 判断用户是否提交认证信息
     * @param userId
     * @return
     */
    public IdCardBean getUserIdcardInfo(int userId){
        List<IdCardBean> mList = idCardMapper.selectList(Condition.create().eq("user_id",userId));
        if(mList!=null && mList.size()>0){
            return mList.get(0);
        }
        return null;
    }

    /**
     * 插入认证信息
     */
    public int insertUserIdcardInfo(UserIdcardRequest request){
        IdCardBean idCardBean = new IdCardBean();
        idCardBean.setCreateTime(new Date());
        idCardBean.setIdcardNums(request.getIdcardNums());
        //待审核
        idCardBean.setState(1);
        idCardBean.setImage(request.getImage());
        idCardBean.setUserName(request.getUserName());
        idCardBean.setUserId(request.getUserId());
        return idCardMapper.insert(idCardBean);
    }
}
